﻿using Furion.DatabaseAccessor;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using iWare.Wms.Core.Enum;

namespace iWare.Wms.Core
{
    /// <summary>
    /// 物料信息
    /// </summary>
    [Table("wms_material")]
    [Comment("物料信息")]
    public class WmsMaterial:DEntityBase, IEntityTypeBuilder<WmsMaterial>
    {

        /// <summary>
        /// 物料名称
        /// </summary>
        [Comment("物料名称")]
        [Required]

        [MaxLength(50)]
        public string MaterialName { get; set; }

        /// <summary>
        /// 物料编号
        /// </summary>
        [Comment("物料编号")]
        [Required]

        [MaxLength(50)]
        public string MaterialNo { get; set; }

        /// <summary>
        /// 物料批次
        /// </summary>
        [Comment("物料批次")]
        [Required]

        [MaxLength(50)]
        public string MaterialBatch { get; set; }

        /// <summary>
        /// 描述
        /// </summary>
        [Comment("描述")]

        [MaxLength(500)]
        public string Description { get; set; }

        /// <summary>
        /// 检验方式;数据字典
        /// </summary>
        [Comment("检验方式")]
        [Required]

        public MaterialInspection InspectionMethod { get; set; }

        /// <summary>
        /// 物料类别;数据字典
        /// </summary>
        [Comment("物料类别")]
        [Required]

        public MaterialType MaterialType { get; set; }

        /// <summary>
        /// 物料规格
        /// </summary>
        [Comment("物料规格")]
        [Required]

        [MaxLength(50)]
        public string MaterialSpec { get; set; }

        /// <summary>
        /// 单位类别;数据字典
        /// </summary>
        [Comment("单位类别")]
        [Required]

        public UnitType UnitType { get; set; }

        /// <summary>
        /// 单位编号;数据字典
        /// </summary>
        [Comment("单位编号")]
        [Required]

        public UnitnoType UnitNo { get; set; }

        /// <summary>
        /// 安全存量
        /// </summary>
        [Comment("安全存量")]

        public decimal Safeqty { get; set; }

        /// <summary>
        /// 是否关键物料;数据字典
        /// </summary>
        [Comment("是否关键物料")]

        public YesOrNot Keymaterials { get; set; }

        /// <summary>
        /// Erp单号
        /// </summary>
        [Comment("Erp单号")]

        [MaxLength(50)]
        public string ErpNo { get; set; }

        /// <summary>
        /// 图号
        /// </summary>
        [Comment("图号")]

        [MaxLength(50)]
        public string GraphNo { get; set; }

        /// <summary>
        /// 品管类别
        /// </summary>
        [Comment("品管类别")]

        [MaxLength(50)]
        public string Qccategory { get; set; }

        /// <summary>
        /// 保质期
        /// </summary>
        [Comment("保质期")]

        public decimal Warranty { get; set; }

        /// <summary>
        /// 最大存量
        /// </summary>
        [Comment("最大存量")]

        public decimal MaxImumqty { get; set; }

        /// <summary>
        /// 最小库龄
        /// </summary>
        [Comment("最小库龄")]

        public decimal MinstorageAge { get; set; }

        /// <summary>
        /// 最大库龄
        /// </summary>
        [Comment("最大库龄")]

        public decimal MaxstorageAge { get; set; }

        public ICollection<WmsMaterialContainer> WmsMaterialContainers { get; set; }


        /// <summary>
        /// 构建一对多的关系
        /// </summary>
        /// <param name="entityBuilder"></param>
        /// <param name="dbContext"></param>
        /// <param name="dbContextLocator"></param>
        public void Configure(EntityTypeBuilder<WmsMaterial> entityBuilder, DbContext dbContext, Type dbContextLocator)
        {
            entityBuilder.HasMany(x => x.WmsMaterialContainers)
                .WithOne(x => x.WmsMaterial)
                .HasForeignKey(x => x.MaterialId).IsRequired(false);
        }
    }
}
